home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16622 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: theory.lcs.mit.edu!wald
  2. From: wald@theory.lcs.mit.edu (David Wald)
  3. Newsgroups: comp.sys.sgi.apps,comp.lang.c++
  4. Subject: Re: SGI's C++ compiler and the boolean type
  5. Followup-To: comp.lang.c++
  6. Date: 11 Apr 1996 14:59:13 GMT
  7. Organization: Theory of Computation, LCS, MIT
  8. Message-ID: <WALD.96Apr11105913@woodpecker.lcs.mit.edu>
  9. References: <4kefm7$oao@ncar.ucar.edu> <4kg6fv$h7k@nic.ftns.no>
  10.     <4khepk$8k1@decaxp.HARVARD.EDU>
  11. NNTP-Posting-Host: woodpecker.lcs.mit.edu
  12. In-reply-to: ccshan@scws44.harvard.edu's message of 10 Apr 1996 23:04:20 GMT
  13.  
  14. In article <4khepk$8k1@decaxp.HARVARD.EDU> ccshan@scws44.harvard.edu
  15. (Chung-chieh Shan) writes:
  16. >According to the proposed standard, true is implicitly casted from
  17. >bool to the integer 1.  Nonzero integers are implicitly casted from
  18. >int to the bool true.
  19. >
  20. >Funny nobody has written an implementation of bool. (AFAIK)
  21.  
  22. That may be because you can't write a class that behaves like the
  23. draft standard bool type.  In the draft standard, all the standard
  24. boolean operators actually return a bool type, and there's no way to
  25. produce that effect with a user-defined type.  E.g.,
  26.  
  27.    int f(int) { return 1; }
  28.    int f(bool) { return 0; }
  29.    int distinguish() { return f( 0 == 1 ); }
  30.  
  31. No user-level definition of bool will make distinguish() return 0, as
  32. it must in the draft standard.
  33.  
  34. -David
  35. -- 
  36. ============================================================================
  37. David Wald      http://theory.lcs.mit.edu/~wald/     wald@theory.lcs.mit.edu
  38. ============================================================================
  39.